home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / tilemap.h < prev    next >
C/C++ Source or Header  |  2000-03-28  |  6KB  |  203 lines

  1. /* tilemap.h */
  2.  
  3. #ifndef TILEMAP_H
  4. #define TILEMAP_H
  5.  
  6. #define ALL_TILEMAPS    0
  7. /* ALL_TILEMAPS may be used with:
  8.     tilemap_update, tilemap_render, tilemap_set_flip, tilemap_mark_all_pixels_dirty
  9. */
  10.  
  11. #define TILEMAP_OPAQUE                0x00
  12. #define TILEMAP_TRANSPARENT            0x01
  13. #define TILEMAP_SPLIT                0x02
  14. #define TILEMAP_BITMASK                0x04
  15. #define TILEMAP_TRANSPARENT_COLOR    0x08
  16. /*
  17.     TILEMAP_SPLIT should be used if the pixels from a single tile
  18.     can appear in more than one plane.
  19.  
  20.     TILEMAP_BITMASK is needed for Namco SystemI
  21. */
  22.  
  23. #define TILEMAP_IGNORE_TRANSPARENCY        0x10
  24. #define TILEMAP_BACK                    0x20
  25. #define TILEMAP_FRONT                    0x40
  26. /*
  27.     when rendering a split layer, pass TILEMAP_FRONT or TILEMAP_BACK or'd with the
  28.     tile_priority value to specify the part to draw.
  29. */
  30.  
  31. #define TILEMAP_BITMASK_TRANSPARENT (0)
  32. #define TILEMAP_BITMASK_OPAQUE ((UINT8 *)~0)
  33.  
  34. struct cached_tile_info {
  35.     const UINT8 *pen_data;
  36.     const UINT16 *pal_data;
  37.     UINT32 pen_usage;
  38.     UINT32 flags;
  39. };
  40.  
  41. extern struct tile_info {
  42.     /*
  43.         you must set tile_info.pen_data, tile_info.pal_data and tile_info.pen_usage
  44.         in the callback.  You can use the SET_TILE_INFO() macro below to do this.
  45.         tile_info.flags and tile_info.priority will be automatically preset to 0,
  46.         games that don't need them don't need to explicitly set them to 0
  47.     */
  48.     const UINT8 *pen_data;
  49.     const UINT16 *pal_data;
  50.     UINT32 pen_usage;
  51.     UINT32 flags;
  52.  
  53.     UINT32 priority;
  54.     UINT8 *mask_data;
  55. } tile_info;
  56.  
  57. #define SET_TILE_INFO(GFX,CODE,COLOR) { \
  58.     const struct GfxElement *gfx = Machine->gfx[(GFX)]; \
  59.     int _code = (CODE) % gfx->total_elements; \
  60.     tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; \
  61.     tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (COLOR)]; \
  62.     tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; \
  63. }
  64.  
  65. /* tile flags, set by get_tile_info callback */
  66. #define TILE_FLIPX                    0x01
  67. #define TILE_FLIPY                    0x02
  68. #define TILE_SPLIT(T)                ((T)<<2)
  69. /* TILE_SPLIT is for use with TILEMAP_SPLIT layers.  It selects transparency type. */
  70. #define TILE_IGNORE_TRANSPARENCY    0x10
  71. /* TILE_IGNORE_TRANSPARENCY is used if you need an opaque tile in a transparent layer */
  72.  
  73. #define TILE_FLIPYX(YX)                (YX)
  74. #define TILE_FLIPXY(XY)                ((((XY)>>1)|((XY)<<1))&3)
  75. /*
  76.     TILE_FLIPYX is a shortcut that can be used by approx 80% of games,
  77.     since yflip frequently occurs one bit higher than xflip within a
  78.     tile attributes byte.
  79. */
  80.  
  81. #define TILE_LINE_DISABLED 0x80000000
  82.  
  83. #ifndef OSD_CPU_H
  84. #include "osd_cpu.h"
  85. #endif
  86.  
  87. extern struct osd_bitmap *priority_bitmap;
  88.  
  89. struct tilemap_mask {
  90.     struct osd_bitmap *bitmask;
  91.     int line_offset;
  92.     UINT8 *data;
  93.     UINT8 **data_row;
  94. };
  95.  
  96. struct tilemap {
  97.     UINT32 (*get_memory_offset)( UINT32 col, UINT32 row, UINT32 num_cols, UINT32 num_rows );
  98.     int *memory_offset_to_cached_index;
  99.     UINT32 *cached_index_to_memory_offset;
  100.     int logical_flip_to_cached_flip[4];
  101.  
  102.     /* callback to interpret video VRAM for the tilemap */
  103.     void (*tile_get_info)( int memory_offset );
  104.  
  105.     UINT32 max_memory_offset;
  106.     int num_tiles;
  107.     int num_logical_rows, num_logical_cols;
  108.     int num_cached_rows, num_cached_cols;
  109.     int cached_tile_width, cached_tile_height, cached_width, cached_height;
  110.  
  111.     struct cached_tile_info *cached_tile_info;
  112.  
  113.     int dx, dx_if_flipped;
  114.     int dy, dy_if_flipped;
  115.     int scrollx_delta, scrolly_delta;
  116.  
  117.     int enable;
  118.     int attributes;
  119.  
  120.     int type;
  121.     int transparent_pen;
  122.     unsigned int transmask[4];
  123.  
  124.     void (*draw)( int, int );
  125.     void (*draw_opaque)( int, int );
  126.  
  127.     UINT8 *priority,    /* priority for each tile */
  128.         **priority_row;
  129.  
  130.     UINT8 *visible; /* boolean flag for each tile */
  131.  
  132.     UINT8 *dirty_vram; /* boolean flag for each tile */
  133.  
  134.     UINT8 *dirty_pixels;
  135.  
  136.     int scroll_rows, scroll_cols;
  137.     int *rowscroll, *colscroll;
  138.  
  139.     int orientation;
  140.     int clip_left,clip_right,clip_top,clip_bottom;
  141.  
  142.     /* cached color data */
  143.     struct osd_bitmap *pixmap;
  144.     int pixmap_line_offset;
  145.  
  146.     struct tilemap_mask *foreground;
  147.     /* for transparent layers, or the front half of a split layer */
  148.  
  149.     struct tilemap_mask *background;
  150.     /* for the back half of a split layer */
  151.  
  152.     struct tilemap *next; /* resource tracking */
  153. };
  154.  
  155. /* don't call these from drivers - they are called from mame.c */
  156. int tilemap_init( void );
  157. void tilemap_close( void );
  158.  
  159. struct tilemap *tilemap_create(
  160.     void (*tile_get_info)( int memory_offset ),
  161.     UINT32 (*get_memory_offset)( UINT32 col, UINT32 row, UINT32 num_cols, UINT32 num_rows ),
  162.     int type,
  163.     int tile_width, int tile_height, /* in pixels */
  164.     int num_cols, int num_rows /* in tiles */
  165. );
  166.  
  167. void tilemap_dispose( struct tilemap *tilemap );
  168. /*    you shouldn't call this in vh_close; all tilemaps will be automatically
  169.     disposed.  tilemap_dispose is supplied for games that need to change
  170.     tile size or cols/rows dynamically.
  171. */
  172.  
  173. void tilemap_set_scroll_cols( struct tilemap *tilemap, int scroll_cols );
  174. void tilemap_set_scroll_rows( struct tilemap *tilemap, int scroll_rows );
  175. /* scroll_rows and scroll_cols default to 1 for XY scrolling */
  176.  
  177. void tilemap_mark_tile_dirty( struct tilemap *tilemap, int memory_offset );
  178. void tilemap_mark_all_tiles_dirty( struct tilemap *tilemap );
  179. void tilemap_mark_all_pixels_dirty( struct tilemap *tilemap );
  180.  
  181. void tilemap_set_scrollx( struct tilemap *tilemap, int row, int value );
  182. void tilemap_set_scrolly( struct tilemap *tilemap, int col, int value );
  183.  
  184. void tilemap_set_scrolldx( struct tilemap *tilemap, int dx, int dx_if_flipped );
  185. void tilemap_set_scrolldy( struct tilemap *tilemap, int dy, int dy_if_flipped );
  186.  
  187. #define TILEMAP_FLIPX 0x1
  188. #define TILEMAP_FLIPY 0x2
  189. void tilemap_set_flip( struct tilemap *tilemap, int attributes );
  190. void tilemap_set_clip( struct tilemap *tilemap, const struct rectangle *clip );
  191. void tilemap_set_enable( struct tilemap *tilemap, int enable );
  192.  
  193. void tilemap_update( struct tilemap *tilemap );
  194. void tilemap_render( struct tilemap *tilemap );
  195. void tilemap_draw( struct osd_bitmap *dest, struct tilemap *tilemap, UINT32 priority );
  196.  
  197. /*********************************************************************/
  198.  
  199. UINT32 tilemap_scan_cols( UINT32 col, UINT32 row, UINT32 num_cols, UINT32 num_rows );
  200. UINT32 tilemap_scan_rows( UINT32 col, UINT32 row, UINT32 num_cols, UINT32 num_rows );
  201.  
  202. #endif
  203.